/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yassp.client;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import yassp.Code;

/**
 *
 * @author pierre
 */
public class ClientApp {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("Launching client...");

        try {
            conn = new Connection();
        } catch (Exception e) {
            System.err.println(e.getMessage());
            return;
        }
        conn.start();
        try {
            root = new Folder("C:\\TestAppli");
        } catch (IOException ex) {
            Logger.getLogger(ClientApp.class.getName()).log(Level.SEVERE, null, ex);
            return;
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(ClientApp.class.getName()).log(Level.SEVERE, null, ex);
            return;
        }

        Command c = new Command(Code.PULLROOT, "");
        conn.pushCommand(c);

        while (true) {
            try {
                Thread.sleep(60 * 1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(ClientApp.class.getName()).log(Level.SEVERE, null, ex);
            }
            if (conn.isCommandQueueEmpty()) {
                root.write();
                Command r = new Command(Code.PUSHROOT, "");
                conn.pushCommand(r);
            }
        }
    }
    public static Connection conn;
    public static Folder root;
}
